package com.dmtt.web.service.impl;

import com.dmtt.web.entity.AgvInfoVo;
import com.dmtt.web.mapper.AgvInfoMapper;
import com.dmtt.web.service.AgvInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class AgvInfoServiceImpl implements AgvInfoService {
    @Autowired
    private AgvInfoMapper agvInfoMapper;


    @Override
    public List<AgvInfoVo> getAgvInfo(AgvInfoVo agvInfoVo) {
        List<AgvInfoVo> agvInfo = agvInfoMapper.findAgvInfo(agvInfoVo);//获取到小车所有信息
        for (AgvInfoVo agvInfoVo1: agvInfo) { //遍历
            //判断小车在线时长是否为空
            if(agvInfoVo1.getCountTime() !=null && !"".equals(agvInfoVo1.getCountTime())){
                agvInfoVo1.setCountTimeStr((agvInfoVo1.getCountTime()/86400));
                if (agvInfoVo1.getName().startsWith("#") && agvInfoVo1.getCountTimeStr() >= 45){
                    Long countTimeStr = agvInfoVo1.getCountTimeStr();
                    Long cycle = agvInfoVo1.getCycle();
                    agvInfoVo1.setCountTimeStr(countTimeStr % cycle);
                }else if (agvInfoVo1.getCountTimeStr() >= 60){
                    Long countTimeStr = agvInfoVo1.getCountTimeStr();
                    Long cycle = agvInfoVo1.getCycle();
                    agvInfoVo1.setCountTimeStr(countTimeStr % cycle);
                }
            }
            //判断状态 状态码等于6小车才是正常行驶，才会有稼动率
            if (agvInfoVo1.getType() == 6){

            }else {
                agvInfoVo1.setCountTime(null);
            }
            //小车只有在在线时长和维护周期不为空的情况下才有维护时长
            if(agvInfoVo1.getCountTimeStr() != null && agvInfoVo1.getCycle()!=null){
                Long countTimeStr = agvInfoVo1.getCountTimeStr();
                Long cycle = agvInfoVo1.getCycle();
                Long sub = cycle-countTimeStr;
                agvInfoVo1.setCycleTime(sub);
            }
        }
        return agvInfo;
    }


}

